package com.wc.算法提高课.C第三章_图论.单源最短路的扩展应用.选择最佳线路;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/12 11:28
 * @description https://www.acwing.com/problem/content/description/1139/
 */
public class Main {
    /**
     * 思路：
     * 建立反向边 / 虚拟原点
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1010, M = 20010, INF = 0x3f3f3f3f;
    static int[] h = new int[N], e = new int[M], ne = new int[M], w = new int[M];
    static int[] dist = new int[N], q = new int[N];
    static boolean[] st = new boolean[N];
    static int[] home = new int[N];
    static int n, m, S, hl, idx = 0;

    public static void main(String[] args) {
        while (sc.hasNext()) {
            n = sc.nextInt();
            if (n == 0) break;
            m = sc.nextInt();
            S = sc.nextInt();
            Arrays.fill(h, 1, n + 1, 0);
            idx = 1;
            while (m-- > 0) {
                int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
                // 反向边
                add(b, a, c);
            }
            hl = sc.nextInt();
            for (int i = 0; i < hl; i++) home[i] = sc.nextInt();
            spfa();
            int res = INF;
            for(int i = 0; i < hl; i++){
                int T = home[i];
                res = Math.min(res, dist[T]);
            }
            if (res == INF) out.println("-1");
            else out.println(res);
        }
        out.flush();
    }

    static void spfa() {
        Arrays.fill(dist, 1, n + 1, INF);
        dist[S] = 0;
        int hh = 0, tt = 1;
        q[0] = S;
        st[S] = true;
        while (hh != tt){
            int t = q[hh++];
            if (hh == N) hh = 0;
            st[t] = false;
            for(int i = h[t]; i > 0; i = ne[i]){
                int j = e[i];
                if (dist[j] > dist[t] + w[i]){
                    dist[j] = dist[t] + w[i];
                    if (!st[j]){
                        q[tt++] = j;
                        if (tt == N) tt = 0;
                        st[j] = true;
                    }
                }
            }
        }
    }

    static void add(int a, int b, int c){
        e[idx] = b;
        w[idx] = c;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
